package main

import (
	"compress/gzip"
	"os"
	"fmt"
	"bufio"
	"io"
	"strings"
)

func main() {
	fileName := "test.gz"
	var reader *bufio.Reader
	file, err := os.Open(fileName)
	if err != nil {
		fmt.Println("Open ERROE:", err)
		os.Exit(1)
	}
	defer file.Close()  // 记得关文件
	gzFile, err := gzip.NewReader(file)
	if err != nil {
		fmt.Println("gz ERROR:", err)
		return
	}
	reader = bufio.NewReader(gzFile)
	for {
		line, err := reader.ReadString('\n')
		fmt.Println(strings.TrimSpace(line))
		if err != nil {
			if err == io.EOF {
				fmt.Println("读取完毕")
				break
			} else {
				fmt.Println("Read ERROR:", err)
				os.Exit(0)
			}
		}
	}
}